$(function () {
    $("#page").load('/html/page.html');
});

function findAll() {
    let data = {
        nickName: $("#nickName").val(),
        sex: $("#sex").find("option:selected").text(),
        type: 3,
        pageSize: $.trim($("#pageSize").val()),
        pageNum: $.trim($("#pageNum").val()),
    }
    let result = myAjax('/user/findAll', "post", data);
    console.log(result);
    show(result.data.list)
    $("#pageCount").html(result.data.number);
}

function show(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        if (data[i].state === 1) {
            data[i].state = "正常";
        } else {
            data[i].state = "封禁";
        }
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="' + data[i].id + '">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].username + '</td>\n' +
            '        <td>' + data[i].nickName + '</td>\n' +
            '        <td>' + data[i].sex + '</td>\n' +
            '        <td>' + data[i].age + '</td>\n' +
            '        <td>' + data[i].icon + '</td>\n' +
            '        <td>' + data[i].phone + '</td>\n' +
            '        <td>' + data[i].state + '</td>\n' +
            '        <td>' + data[i].createTime + '</td>\n' +
            '        <td><input type="button" style="width: 60px;background-color: darkcyan;border-radius: 5px" value="编辑" onclick="edit(' + data[i].id + ')"></td>' +
            '    </tr>';
    }
    $("#findAll").html(html);
}

function edit(id) {
//需要弹出界面
    sessionStorage.setItem("teacherId",id);
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'编辑用户--老师',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/user/studentEdit.html','no'],
    })
}
function addStudent() {
    //弹出一个页面层
    layer.open({
        type: 2,
        anim:3,
        title:'添加老师',
        area: ['600px', '600px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/user/addTeacher.html','no'],
    })
}